package com.example.sunlight.interneteverything.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.sunlight.interneteverything.R;

import java.util.List;

/**
 * Created by Admintor on 2017/9/28.
 */

public class TrafficBaseAdapter extends BaseAdapter {
    List<String[]> list;
    Context context;

    public TrafficBaseAdapter(List<String[]> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHodler hodler = null;
        if (convertView == null) {
            hodler = new ViewHodler();
            convertView = LayoutInflater.from(context).inflate(R.layout.traffic_item, null);
            hodler.title = (TextView) convertView.findViewById(R.id.title);
            hodler.msg = (TextView) convertView.findViewById(R.id.msg);
            hodler.change = (TextView) convertView.findViewById(R.id.chage);
            convertView.setTag(hodler);
        } else {
            hodler = (ViewHodler) convertView.getTag();
        }
        hodler.title.setText(list.get(position)[0]);
        hodler.msg.setText(list.get(position)[1]);
        hodler.change.setText(list.get(position)[2]);
        return convertView;
    }

    class ViewHodler {
        private TextView title;
        private TextView msg;
        private TextView change;

    }
}
